<?php
/*
 * @Author: your name
 * @Date: 2020-10-14 09:43:52
 * @LastEditTime: 2020-12-28 10:07:39
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙虚拟规则
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/FirewallVirtualRuleController.php
 */

namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\controller\BaseController;
use app\adminapiv3\service\module_manage\netfilter\FirewallVirtualRuleService;
use think\facade\Request;

class FirewallVirtualRuleController extends BaseController
{
    /**
    * @name: 虚拟规则 
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-18 10:43:27
     */
    public function virtualList ($host_id)
    {
        $input = Request::only(['src_ip','dest_ip','dest_port','src_port','have_mac_addr','status','process','protocols','direction','alias'], 'post');
        $input['host_id'] = $host_id;
        $this->validate($input, 'FirewallVirtualRule.listFilter');
        
        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $data = $FirewallVirtualRuleService->virtualRuleList($input);

        return $this->jsonOutPut($data);
    }

    /**
     * @name: 添加规则 
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-18 10:45:19
     */
    public function virtualAdd ()
    {
        $input = Request::only(['host_id','src_ip','dest_ip','dest_port','src_port','process','protocols','direction','alias'], 'post');
        $this->validate($input, 'FirewallVirtualRule.add');
        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $FirewallVirtualRuleService->virtualRuleAdd($input);

        return $this->jsonOutPut();
    }

    /**
     * @name: 修改
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-18 10:45:45
     */
    public function virtualModify ($host_id)
    {
        $input = Request::only(['id','fid','host_id','src_ip','dest_ip','dest_port','src_port','process','protocols','direction','alias'], 'post');
        $input['host_id'] = $host_id;
        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $FirewallVirtualRuleService->virtualRuleModify($input);

        return $this->jsonOutPut();
    }

    /**
     * @name: 虚拟规则删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-18 10:47:14
     */
    public function virtualDelete ($host_id)
    {
        $input = Request::only(['fid']);
        $input['host_id'] = $host_id;
        $this->validate($input, 'FirewallVirtualRule.fidRequire');

        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $FirewallVirtualRuleService->virtualRuleDelete($input);

        return $this->jsonOutPut();
    }

    /**
     * @name: 启用虚拟规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-12 13:52:58
     */
    public function virtualOn ($host_id)
    {
        $input = Request::only(['fid']);
        $input['host_id'] = $host_id;
        $this->validate($input, 'FirewallVirtualRule.fidRequire');

        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $FirewallVirtualRuleService->virtualRuleOn($input);

        return $this->jsonOutPut();
    }

    /**
     * @name: 关闭虚拟规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-12 13:52:58
     */
    public function virtualOff ($host_id)
    {
        $input = Request::only(['fid']);
        $input['host_id'] = $host_id;
        $this->validate($input, 'FirewallVirtualRule.fidRequire');

        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $FirewallVirtualRuleService->virtualRuleOff($input);

        return $this->jsonOutPut();
    }


        /**
     * @name: 虚拟规则命中日志列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-08 15:18:39
     */
    public function virtualRuleHitLogList ($host_id)
    {
        $input = Request::only(['src_ip','dest_ip','dest_port','src_port','direction','rule_name'],'post');
        $input['host_id'] = $host_id;
        $FirewallVirtualRuleService = new FirewallVirtualRuleService();
        $data = $FirewallVirtualRuleService->virtualRuleHitLog($input);

        return $this->jsonOutPut($data);
    }
}